//
//  LoginUserViewController.m
//  ShangHaiTuJI
//
//  Created by xiaoxiangtuji on 2017/7/18.
//  Copyright © 2017年 xiaoxiangtuji. All rights reserved.
//

#import "LoginUserViewController.h"
#import "RegisterNewPhoneCodeViewController.h"
#import "VerfityCodeViewController.h"
#import "ZAlertView.h"
#import "ZAlertViewManager.h"
#import <UMSocialCore/UMSocialCore.h>
#import <UShareUI/UMSocialUIUtility.h>
#import "HomepageViewController.h"
#import "UIButton+LZCategory.h"
#import "WXApiObject.h"
#import "WXApi.h"
#import "CustomGuideView.h"
@interface LoginUserViewController ()<UITextFieldDelegate,UIViewControllerTransitioningDelegate>
@property(nonatomic,strong)UITextField *phoneTextFiled;
@property(nonatomic,strong)UITextField *secrectTextFiled;
@property(nonatomic,strong)UIView *view2;
@property(nonatomic,strong)UIView *view3;


@property(nonatomic,strong)UIButton *QQBtn;
@property(nonatomic,strong)UIButton *wechatBtn;
@end

@implementation LoginUserViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self createLoginVcUI];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(wechatLogtoin:) name:@"sendUnionid" object:nil];
    // Do any additional setup after loading the view.
}
-(void)viewWillAppear:(BOOL)animated{
    CGFloat offset = 0;
    [self.navigationController.navigationBar
     setBackgroundImage:[self imageWithColor:[UIColor colorWithRed:255/255.0 green:201/255.0 blue:31/255.0 alpha:(offset / 64)>0.99?0.99:(offset / 64)]] forBarMetrics:UIBarMetricsDefault];
    [self.navigationController.navigationBar
     setShadowImage:[UIImage new]];
    self.tabBarController.tabBar.hidden = YES;
    self.phoneTextFiled.text = [[NSUserDefaults standardUserDefaults] objectForKey:@"PHONE"];
    self.secrectTextFiled.text = [[NSUserDefaults standardUserDefaults] objectForKey:@"SECRECT"];
    [self monitorNetwork];
}
-(void)viewWillDisappear:(BOOL)animated{
    [self.navigationController.navigationBar setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault];
    [self.navigationController.navigationBar setShadowImage:nil];
    self.tabBarController.tabBar.hidden = NO;
}
-(UIImage*) imageWithColor:(UIColor*) color
{
    CGRect rect=CGRectMake(0.0f, 0.0f, 1.0f, 1.0f);
    UIGraphicsBeginImageContext(rect.size);
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextSetFillColorWithColor(context, [color CGColor]);
    CGContextFillRect(context, rect);
    UIImage *theImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return theImage;
    
}
-(void)createLoginVcUI{
    self.view.backgroundColor = [UIColor whiteColor];
    //****************头部背景*******************************
    UIImageView *titleImageView = [[UIImageView alloc] init];
    titleImageView.image = [UIImage imageNamed:@"新新背景"];
    titleImageView.userInteractionEnabled = YES;
    [self.view addSubview:titleImageView];
    [titleImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.view.mas_top).offset(0);
        make.right.equalTo(self.view.mas_right);
        make.left.equalTo(self.view.mas_left);
        make.height.mas_equalTo(scaleTopAndBottom(172));
    }];
    UIButton *backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [backBtn addTarget:self action:@selector(dismissTheCurrentView) forControlEvents:UIControlEventTouchUpInside];
//    backBtn.backgroundColor = [UIColor redColor];
    [titleImageView addSubview:backBtn];
    [backBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(titleImageView.mas_left).offset(scaleLeftAndRight(10));
        make.size.mas_equalTo(CGSizeMake(30, 30));
        make.top.equalTo(titleImageView.mas_top).offset(scaleTopAndBottom(30));
    }];
    UIView *view1 = [[UIView alloc] init];
    view1.backgroundColor = ZColorRGB(244.0, 190.0, 65.0);
    [self.view addSubview:view1];
    [view1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view.mas_left).offset(scaleLeftAndRight(15.0));
        make.top.equalTo(titleImageView.mas_bottom).offset(scaleTopAndBottom(20.0));
        make.width.mas_equalTo(scaleLeftAndRight(5));
        make.height.mas_equalTo(scaleTopAndBottom(20));
    }];
    UILabel *logLabel = [[UILabel alloc] init];
    logLabel.text = @"登录";
    [self.view addSubview:logLabel];
    [logLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(view1.mas_right).offset(scaleLeftAndRight(5));
        make.right.equalTo(self.view.mas_right);
        make.height.mas_equalTo(scaleTopAndBottom(20));
        make.top.equalTo(titleImageView.mas_bottom).offset(scaleTopAndBottom(20.0));
    }];
    //******************第一个输入框布局*********************
    UIImageView *phoneImage = [[UIImageView alloc] init];
    phoneImage.image = [UIImage imageNamed:@"账号"];
    [self.view addSubview:phoneImage];
    [phoneImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view.mas_left).offset(scaleLeftAndRight(40));
        make.top.equalTo(logLabel.mas_bottom).offset(scaleTopAndBottom(35));
        make.width.mas_equalTo(scaleLeftAndRight(15));
        make.height.mas_equalTo(scaleTopAndBottom(15));
    }];
    UIImageView *clearImage = [[UIImageView alloc] init];
    clearImage.image = [UIImage imageNamed:@"SHANCHU"];
    clearImage.userInteractionEnabled = YES;
    UITapGestureRecognizer *clearTaop = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(clearIntextContent)];
    [clearImage addGestureRecognizer:clearTaop];
    [self.view addSubview:clearImage];
    [clearImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.view.mas_right).offset(scaleLeftAndRight(-40));
        make.top.equalTo(logLabel.mas_bottom).offset(scaleTopAndBottom(35));
        make.width.mas_equalTo(scaleLeftAndRight(15));
        make.height.mas_equalTo(scaleTopAndBottom(15));
    }];
    self.phoneTextFiled = [[UITextField alloc] init];
    self.phoneTextFiled.delegate = self;
    self.phoneTextFiled.placeholder = @"请输入手机号码";
    [self.view addSubview:self.phoneTextFiled];
    [self.phoneTextFiled mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(phoneImage.mas_right).offset(scaleLeftAndRight(5));
        make.top.equalTo(logLabel.mas_bottom).offset(scaleTopAndBottom(28));
        make.height.mas_equalTo(scaleTopAndBottom(30));
        make.right.equalTo(clearImage.mas_left).offset(scaleLeftAndRight(-5));
    }];
    self.view2 = [[UIView alloc] init];
    [self.view addSubview:self.view2];
    self.view2.backgroundColor = [UIColor lightGrayColor];
    [self.view2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.view.mas_right).offset(scaleLeftAndRight(-30));
        make.left.equalTo(self.view.mas_left).offset(scaleLeftAndRight(30));
        make.top.equalTo(self.phoneTextFiled.mas_bottom).offset(scaleTopAndBottom(0));
        make.height.mas_equalTo(scaleTopAndBottom(1));
    }];
    ////******************第二个输入框布局*********************
    UIImageView *secrectImage = [[UIImageView alloc] init];
    secrectImage.image = [UIImage imageNamed:@"密码"];
    [self.view addSubview:secrectImage];
    [secrectImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view.mas_left).offset(scaleLeftAndRight(40));
        make.top.equalTo(self.view2.mas_bottom).offset(scaleTopAndBottom(35));
        make.width.mas_equalTo(scaleLeftAndRight(15));
        make.height.mas_equalTo(scaleTopAndBottom(15));
    }];
    UIButton *visualImageBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [visualImageBtn setImage:[UIImage imageNamed:@"眼睛"] forState:UIControlStateNormal];
    [visualImageBtn addTarget:self action:@selector(visualInputWord:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:visualImageBtn];
    [visualImageBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.view.mas_right).offset(scaleLeftAndRight(-40));
        make.top.equalTo(self.view2.mas_bottom).offset(scaleTopAndBottom(35));
        make.width.mas_equalTo(scaleLeftAndRight(15));
        make.height.mas_equalTo(scaleTopAndBottom(15));
    }];
    self.secrectTextFiled = [[UITextField alloc] init];
    self.secrectTextFiled.delegate = self;
    self.secrectTextFiled.placeholder = @"请输入密码";
    self.secrectTextFiled.secureTextEntry = YES;
    [self.view addSubview:self.secrectTextFiled];
    [self.secrectTextFiled mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(secrectImage.mas_right).offset(scaleLeftAndRight(5));
        make.top.equalTo(self.view2.mas_bottom).offset(scaleTopAndBottom(28));
        make.height.mas_equalTo(scaleTopAndBottom(30));
        make.right.equalTo(visualImageBtn.mas_left).offset(scaleLeftAndRight(-5));
    }];
    self.view3 = [[UIView alloc] init];
    [self.view addSubview:self.view3];
    self.view3.backgroundColor = [UIColor lightGrayColor];
    [self.view3 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.view.mas_right).offset(scaleLeftAndRight(-30));
        make.left.equalTo(self.view.mas_left).offset(scaleLeftAndRight(30));
        make.top.equalTo(self.secrectTextFiled.mas_bottom).offset(0);
        make.height.mas_equalTo(scaleTopAndBottom(1));
    }];
    UIButton *loginBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [loginBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [loginBtn setTitle:@"登  录" forState:UIControlStateNormal];
    loginBtn.titleLabel.font = [UIFont systemFontOfSize:20];
    [loginBtn addTarget:self action:@selector(userInformationLogin) forControlEvents:UIControlEventTouchUpInside];
    loginBtn.backgroundColor = COLOR_HEX(0xffc91f);
    loginBtn.layer.cornerRadius = scaleTopAndBottom(25);
    loginBtn.layer.masksToBounds = YES;
    [self.view addSubview:loginBtn];
    [loginBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(scaleTopAndBottom(50));
        make.top.equalTo(self.view3.mas_bottom).offset(scaleTopAndBottom(50));
        make.left.equalTo(self.view.mas_left).offset(scaleLeftAndRight(40));
        make.right.equalTo(self.view.mas_right).offset(scaleLeftAndRight(-40));
    }];
    ////*******************登录下面视图***************
    UIView *view4 = [[UIView alloc] init];
    view4.backgroundColor = [UIColor blackColor];
    [self.view addSubview:view4];
    [view4 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.view.mas_centerX);
        make.top.equalTo(loginBtn.mas_bottom).offset(scaleTopAndBottom(40));
        make.height.mas_equalTo(scaleTopAndBottom(20));
        make.width.mas_equalTo(scaleLeftAndRight(1));
    }];
    UIButton *forgetBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [forgetBtn setTitle:@"忘记密码?" forState:UIControlStateNormal];
    forgetBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
    [forgetBtn setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
    [forgetBtn addTarget:self action:@selector(forgetSecrectAndFindSecrect) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:forgetBtn];
    [forgetBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(loginBtn.mas_bottom).offset(scaleTopAndBottom(40));
        make.right.equalTo(view4.mas_left).offset(scaleLeftAndRight(-30));
        make.height.mas_equalTo(scaleTopAndBottom(20));
        make.width.mas_equalTo(scaleLeftAndRight(110));
    }];
    UIButton *registerBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [registerBtn setTitle:@"现在注册>" forState:UIControlStateNormal];
    [registerBtn setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
    forgetBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
    [registerBtn addTarget:self action:@selector(gotoRegisterPhone) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:registerBtn];
    [registerBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(loginBtn.mas_bottom).offset(scaleTopAndBottom(40));
        make.left.equalTo(view4.mas_right).offset(scaleLeftAndRight(20));
        make.height.mas_equalTo(scaleTopAndBottom(20));
        make.width.mas_equalTo(scaleLeftAndRight(110));
    }];
    UILabel *thirdLabel = [[UILabel alloc] init];
    thirdLabel.text = @"使用第三方登录";
    thirdLabel.font = [UIFont systemFontOfSize:14];
    thirdLabel.textColor = [UIColor lightGrayColor];
    thirdLabel.textAlignment = NSTextAlignmentCenter;
    [self.view addSubview:thirdLabel];
    [thirdLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.view.mas_centerX);
        make.top.equalTo(view4.mas_bottom).offset(scaleTopAndBottom(30));
        make.height.mas_equalTo(scaleTopAndBottom(15));
    }];
    UIView *view5 = [[UIView alloc] init];
    view5.backgroundColor = [UIColor lightGrayColor];
    [self.view addSubview:view5];
    [view5 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(scaleTopAndBottom(1));
        make.left.equalTo(self.view.mas_left).offset(scaleLeftAndRight(100));
        make.width.mas_equalTo(scaleLeftAndRight(25));
        make.top.equalTo(view4.mas_bottom).offset(scaleLeftAndRight(37.5));
    }];
    UIView *view6 = [[UIView alloc] init];
    view6.backgroundColor = [UIColor lightGrayColor];
    [self.view addSubview:view6];
    [view6 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(scaleTopAndBottom(1));
        make.right.equalTo(self.view.mas_right).offset(scaleLeftAndRight(-100));
        make.width.mas_equalTo(scaleLeftAndRight(25));
        make.top.equalTo(view4.mas_bottom).offset(scaleLeftAndRight(37.5));
    }];
    self.QQBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [_QQBtn setImage:[UIImage imageNamed:@"QQ"] forState:UIControlStateNormal];
    [_QQBtn addTarget:self action:@selector(logQQInfomation) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:_QQBtn];
    [_QQBtn mas_makeConstraints:^(MASConstraintMaker *make) {
     make.left.equalTo(self.view.mas_left).offset(scaleLeftAndRight(120));
        make.top.equalTo(view5.mas_bottom).offset(scaleTopAndBottom(30));
        make.height.mas_equalTo(scaleTopAndBottom(45));
        make.width.mas_equalTo(scaleLeftAndRight(45));
    }];
    UILabel *QQLabel = [[UILabel alloc] init];
    QQLabel.text = @"QQ";
    QQLabel.textAlignment = NSTextAlignmentCenter;
    [self.view addSubview:QQLabel];
    [QQLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(_QQBtn.mas_centerX);
        make.top.equalTo(_QQBtn.mas_bottom).offset(scaleTopAndBottom(10));
        make.height.mas_equalTo(scaleTopAndBottom(20));
        make.width.mas_equalTo(scaleLeftAndRight(45));
    }];
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
        if ([WXApi isWXAppInstalled]) {
            NSLog(@"安装了微信");
            self.wechatBtn = [UIButton buttonWithType:UIButtonTypeCustom];
            [_wechatBtn setImage:[UIImage imageNamed:@"WEIIXN"] forState:UIControlStateNormal];
            [_wechatBtn addTarget:self action:@selector(wechatLogIn) forControlEvents:UIControlEventTouchUpInside];
            [self.view addSubview:_wechatBtn];
            [_wechatBtn mas_makeConstraints:^(MASConstraintMaker *make) {
                make.right.equalTo(self.view.mas_right).offset(scaleLeftAndRight(-120));
                make.top.equalTo(view5.mas_bottom).offset(scaleTopAndBottom(30));
                make.height.mas_equalTo(scaleTopAndBottom(45));
                make.width.mas_equalTo(scaleLeftAndRight(45));
            }];
            UILabel *wechatLabel = [[UILabel alloc] init];
            wechatLabel.textAlignment = NSTextAlignmentCenter;
            [self.view addSubview:wechatLabel];
            wechatLabel.text = @"微信";
            [wechatLabel mas_makeConstraints:^(MASConstraintMaker *make) {
                make.centerX.equalTo(_wechatBtn.mas_centerX);
                make.top.equalTo(_wechatBtn.mas_bottom).offset(scaleTopAndBottom(10));
                make.height.mas_equalTo(scaleTopAndBottom(20));
                make.width.mas_equalTo(scaleLeftAndRight(45));
            }];
        }else{
            [_QQBtn mas_makeConstraints:^(MASConstraintMaker *make) {
                make.centerX.equalTo(self.view.mas_centerX);
                make.top.equalTo(view5.mas_bottom).offset(scaleTopAndBottom(30));
                make.height.mas_equalTo(scaleTopAndBottom(45));
                make.width.mas_equalTo(scaleLeftAndRight(45));
            }];
            [QQLabel mas_makeConstraints:^(MASConstraintMaker *make) {
                make.centerX.equalTo(_QQBtn.mas_centerX);
                make.top.equalTo(_QQBtn.mas_bottom).offset(scaleTopAndBottom(10));
                make.height.mas_equalTo(scaleTopAndBottom(20));
                make.width.mas_equalTo(scaleLeftAndRight(45));
            }];
            NSLog(@"没有安装了微信");
        }
    }else if([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPhone){
        self.wechatBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_wechatBtn setImage:[UIImage imageNamed:@"WEIIXN"] forState:UIControlStateNormal];
        [_wechatBtn addTarget:self action:@selector(wechatLogIn) forControlEvents:UIControlEventTouchUpInside];
        [self.view addSubview:_wechatBtn];
        [_wechatBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self.view.mas_right).offset(scaleLeftAndRight(-120));
            make.top.equalTo(view5.mas_bottom).offset(scaleTopAndBottom(30));
            make.height.mas_equalTo(scaleTopAndBottom(45));
            make.width.mas_equalTo(scaleLeftAndRight(45));
        }];
        UILabel *wechatLabel = [[UILabel alloc] init];
        wechatLabel.textAlignment = NSTextAlignmentCenter;
        [self.view addSubview:wechatLabel];
        wechatLabel.text = @"微信";
        [wechatLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self.view.mas_right).offset(scaleLeftAndRight(-120));
            make.top.equalTo(_wechatBtn.mas_bottom).offset(scaleTopAndBottom(10));
            make.height.mas_equalTo(scaleTopAndBottom(20));
            make.width.mas_equalTo(scaleLeftAndRight(45));
        }];
    }




}
-(void)dismissTheCurrentView{
    [self dismissViewControllerAnimated:YES completion:^{
        
    }];
}
#pragma mark -注册账号
-(void)gotoRegisterPhone{
    RegisterNewPhoneCodeViewController *registerVc = [[RegisterNewPhoneCodeViewController alloc] init];
    registerVc.headerTitile = @"手机号注册";
    registerVc.isRegister = YES;
    registerVc.type = @"0";
    registerVc.transitioningDelegate = self;
    registerVc.modalTransitionStyle = UIModalPresentationCustom;
    [self presentViewController:registerVc animated:YES completion:nil];

}
#pragma mark -忘记密码
-(void)forgetSecrectAndFindSecrect{

//    VerfityCodeViewController *vc = [[VerfityCodeViewController alloc] init];
//    vc.backStr = @"找回密码";
//    if ([[NSUserDefaults standardUserDefaults] objectForKey:@"phoneNumber"]) {
//        AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
//        manager.responseSerializer = [AFHTTPResponseSerializer serializer];
//        NSString *url = ServerIp@"/customerApp/getSmsMail";
//        NSString *phoneNumber = [[NSUserDefaults standardUserDefaults] objectForKey:@"phoneNumber"];
//        NSDictionary *dict = @{@"phoneNumber":phoneNumber,@"type":@"1"};
//        [manager POST:url parameters:dict progress:^(NSProgress * _Nonnull uploadProgress) {
//            
//        } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
//            
//        } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
//            
//        }];
//        [self presentViewController:vc animated:YES completion:^{
//            
//        }];
//
//    }
    RegisterNewPhoneCodeViewController *registerVc = [[RegisterNewPhoneCodeViewController alloc] init];
    registerVc.headerTitile = @"找回密码";
    registerVc.type = @"1";
    registerVc.isRegister = NO;
    registerVc.transitioningDelegate = self;
    registerVc.modalTransitionStyle = UIModalPresentationCustom;
    [self presentViewController:registerVc animated:YES completion:^{
        
    }];

}
#pragma mark -输入框的代理方法
-(BOOL)textFieldShouldReturn:(UITextField *)textField{
    [textField resignFirstResponder];
    self.view2.backgroundColor = [UIColor lightGrayColor];
    self.view3.backgroundColor = [UIColor lightGrayColor];
    return YES;
}
#pragma mark -清空输入内容
-(void)clearIntextContent{
    self.phoneTextFiled.text = @"";
}
#pragma mark -密码可见
-(void)visualInputWord:(UIButton *)btn{
    btn.selected = !btn.selected;
    if (btn.selected) {
        [btn setImage:[UIImage imageNamed:@"眼镜后"] forState:UIControlStateNormal];
        self.secrectTextFiled.secureTextEntry = NO;
    }else{
        [btn setImage:[UIImage imageNamed:@"眼睛"] forState:UIControlStateNormal];
        self.secrectTextFiled.secureTextEntry = YES;
    }
    
}
-(BOOL)textFieldShouldBeginEditing:(UITextField *)textField{
    if ([textField isEqual:self.phoneTextFiled]) {
        self.view2.backgroundColor = COLOR_HEX(0xffc91f);
        self.view3.backgroundColor = [UIColor lightGrayColor];
    }else{
        self.view2.backgroundColor = [UIColor lightGrayColor];
        self.view3.backgroundColor = COLOR_HEX(0xffc91f);
    }
    return YES;
}
#pragma mark -网络检测
-(void)monitorNetwork{

    AFNetworkReachabilityManager *netMonitor = [AFNetworkReachabilityManager sharedManager];
    [netMonitor startMonitoring];
    [netMonitor
     setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
         switch (status) {
             case AFNetworkReachabilityStatusUnknown:
                 NSLog(@"未识别的网络");
                 break;
                 
             case AFNetworkReachabilityStatusNotReachable:{
                    [[ZAlertViewManager shareManager] showWithType:1];
                 NSLog(@"无网络连接");
             }
                 break;
                 
             case AFNetworkReachabilityStatusReachableViaWWAN:
             {
                   [[ZAlertViewManager shareManager] dismissWithTime:0];
                 NSLog(@"2G,3G,4G...的网络");
             }
                 
                 break;
                 
             case AFNetworkReachabilityStatusReachableViaWiFi:
             {
                    [[ZAlertViewManager shareManager] dismissWithTime:0];
                   NSLog(@"wifi的网络");
             }
                 break;
             default:
                 break;
         }
     }];
}
#pragma mark -用户信息登录
-(void)userInformationLogin{
    [self monitorNetwork];
    if ([self.phoneTextFiled.text  isEqual: @""] || [self.secrectTextFiled.text isEqual: @""]) {
        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"用户名或者账号不能为空" message:nil delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
        [alertView show];
    }else{
        AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
        manager.responseSerializer = [AFHTTPResponseSerializer serializer];
        NSString *url = ServerIp@"/customerApp/customerLogin";
        NSDictionary *param = @{@"phoneNumber":self.phoneTextFiled.text,@"passWord":self.secrectTextFiled.text,@"type":@"0"};
        [manager POST:url parameters:param progress:^(NSProgress * _Nonnull uploadProgress) {
            
        } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
            NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableContainers error:nil];
            if ([dict[@"result"] integerValue] == 0) {
                NSDictionary *customerDic = dict[@"customer"];
                [[NSUserDefaults standardUserDefaults] setObject:customerDic[@"sessionId"] forKey:@"sessionId"];
                [[NSUserDefaults standardUserDefaults] setObject:self.phoneTextFiled.text forKey:@"PHONE"];
                [[NSUserDefaults standardUserDefaults] setObject:self.secrectTextFiled.text forKey:@"SECRECT"];
                [[NSUserDefaults standardUserDefaults] setObject:customerDic[@"interest"] forKey:@"INTERST"];
                [[NSUserDefaults standardUserDefaults] setObject:customerDic[@"name"] forKey:@"NAME"];
                [[NSUserDefaults standardUserDefaults] setObject:customerDic[@"pic"][@"path"] forKey:@"HEADERICON"];
                [[NSUserDefaults standardUserDefaults] setObject:self.chooseTypeId forKey:@"Identity"];
                [[NSUserDefaults standardUserDefaults] setObject:customerDic[@"autograph"] forKey:@"AUTOGRA"];
                [[NSUserDefaults standardUserDefaults] setObject:customerDic[@"gender"] forKey:@"GENDER"];
                [self chooseUserTypeToIdentfier:self.chooseTypeId];
                [[NSUserDefaults standardUserDefaults] synchronize];
                //********************测试登录**************
//                 [self dismissViewControllerAnimated:YES completion:nil];
//                HomepageViewController *homePage = [[HomepageViewController alloc] init];
//                [self presentViewController:homePage animated:YES completion:^{
//
//                }];
                
                NSLog(@"%@",dict);
            }else{
                UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:dict[@"msg"] message:nil delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
                [alertView show];
            }
        } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
            
        }];

    }


}
#pragma mark -QQ登录
-(void)logQQInfomation{
    [self getAuthWithUserInfoFromQQ];
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
        
    }
}

- (void)getAuthWithUserInfoFromQQ
{
    [[UMSocialManager defaultManager] getUserInfoWithPlatform:UMSocialPlatformType_QQ currentViewController:nil completion:^(id result, NSError *error) {
        if (error) {
            NSLog(@"无论什么原因，它不同意");
        } else {
            UMSocialUserInfoResponse *resp = result;
            NSLog(@"获取到的所有数据信息%@",resp);
            // 授权信息
            NSLog(@"QQ uid: %@", resp.uid);
            NSLog(@"QQ openid: %@", resp.openid);
            NSLog(@"QQ unionid: %@", resp.unionId);
            NSLog(@"QQ accessToken: %@", resp.accessToken);
            NSLog(@"QQ expiration: %@", resp.expiration);
            // 用户信息
            NSLog(@"QQ name: %@", resp.name);
            NSLog(@"QQ iconurl: %@", resp.iconurl);
            NSLog(@"QQ gender: %@", resp.unionGender);
            // 第三方平台SDK源数据
            NSLog(@"QQ originalResponse: %@", resp.originalResponse);
            AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
            manager.responseSerializer = [AFHTTPResponseSerializer serializer];
            NSString *url = ServerIp@"/customerApp/customerLogin";
            NSDictionary *param = @{@"qqUnionId":resp.openid,@"type":@"2"};
            [manager POST:url parameters:param progress:^(NSProgress * _Nonnull uploadProgress) {
                
            } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
                NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableContainers error:nil];
                NSLog(@"%@",dict[@"msg"]);
                if ([dict[@"result"] integerValue] == 0) {
                    NSDictionary *customerDic = dict[@"customer"];
                    [[NSUserDefaults standardUserDefaults] setObject:customerDic[@"sessionId"] forKey:@"sessionId"];
                    [[NSUserDefaults standardUserDefaults] setObject:self.phoneTextFiled.text forKey:@"PHONE"];
                    [[NSUserDefaults standardUserDefaults] setObject:self.secrectTextFiled.text forKey:@"SECRECT"];
                    [[NSUserDefaults standardUserDefaults] setObject:customerDic[@"interest"] forKey:@"INTERST"];
                    [[NSUserDefaults standardUserDefaults] setObject:customerDic[@"name"] forKey:@"NAME"];
                    [[NSUserDefaults standardUserDefaults] setObject:customerDic[@"pic"][@"path"] forKey:@"HEADERICON"];
                    [[NSUserDefaults standardUserDefaults] setObject:self.chooseTypeId forKey:@"Identity"];
                        [[NSUserDefaults standardUserDefaults] setObject:customerDic[@"autograph"] forKey:@"AUTOGRA"];
                        [[NSUserDefaults standardUserDefaults] setObject:customerDic[@"gender"] forKey:@"GENDER"];
                    [[NSUserDefaults standardUserDefaults] synchronize];
                   [self chooseUserTypeToIdentfier:self.chooseTypeId];
                    //********************登录**************
//                    HomepageViewController *homePage = [[HomepageViewController alloc] init];
//                    [self presentViewController:homePage animated:YES completion:^{
//
//                    }];

                    NSLog(@"%@",dict);
                }
            } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
                NSLog(@"失败了为什么%@",error);
            }];

        }
    }];
}

#pragma mark -微信登录
-(void)wechatLogIn{
    [self wechatGetAution];
}
-(void)wechatGetAution{
    SendAuthReq *req = [[SendAuthReq alloc] init];
    req.scope = @"snsapi_userinfo";
    req.openID = @"wxd435477ce5bf9ebe";
    req.state = @"ShangHaiAoDing.ShangHaiTuJI";
    if ([WXApi isWXAppInstalled]) {
        NSLog(@"安装了微信");
        [WXApi sendAuthReq:req viewController:self delegate:(id)self];
    }else{
        [WXApi sendAuthReq:req viewController:self delegate:(id)self];
        NSLog(@"没有安装了微信");
    }

}
-(void)wechatLogtoin:(NSNotification *)infor{
    NSString *uiniId =  [[NSUserDefaults standardUserDefaults] objectForKey:@"unionid"];
    NSLog(@"哈哈拿到了%@",uiniId);
    // 第三方平台SDK源数据
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    manager.responseSerializer = [AFHTTPResponseSerializer serializer];
    NSString *url = ServerIp@"/customerApp/customerLogin";
    NSDictionary *param = @{@"wxUnionId":uiniId,@"type":@"1"};
    [manager POST:url parameters:param progress:^(NSProgress * _Nonnull uploadProgress) {
        
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableContainers error:nil];
        NSLog(@"%@",dict[@"msg"]);
        NSLog(@"%@",dict);
        if ([dict[@"result"] integerValue] == 0) {
            NSDictionary *customerDic = dict[@"customer"];
            [[NSUserDefaults standardUserDefaults] setObject:customerDic[@"sessionId"] forKey:@"sessionId"];
            [[NSUserDefaults standardUserDefaults] setObject:self.phoneTextFiled.text forKey:@"PHONE"];
            [[NSUserDefaults standardUserDefaults] setObject:self.secrectTextFiled.text forKey:@"SECRECT"];
            [[NSUserDefaults standardUserDefaults] setObject:customerDic[@"interest"] forKey:@"INTERST"];
            [[NSUserDefaults standardUserDefaults] setObject:customerDic[@"name"] forKey:@"NAME"];
            [[NSUserDefaults standardUserDefaults] setObject:customerDic[@"pic"][@"path"] forKey:@"HEADERICON"];
            [[NSUserDefaults standardUserDefaults] setObject:self.chooseTypeId forKey:@"Identity"];
            [[NSUserDefaults standardUserDefaults] setObject:customerDic[@"autograph"] forKey:@"AUTOGRA"];
                [[NSUserDefaults standardUserDefaults] setObject:customerDic[@"gender"] forKey:@"GENDER"];
            [[NSUserDefaults standardUserDefaults] synchronize];
             [self chooseUserTypeToIdentfier:self.chooseTypeId];
            //********************登录**************
//            HomepageViewController *homePage = [[HomepageViewController alloc] init];
//            [self presentViewController:homePage animated:YES completion:^{
//
//            }];
//            [self dismissViewControllerAnimated:YES completion:nil];
            NSLog(@"%@",dict);
        }
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        NSLog(@"失败了为什么%@",error);
    }];

}
/**
 根据选择类型选择身份认证
 
 @param identity 身份ID
 */
-(void)chooseUserTypeToIdentfier:(NSString *)identity{
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    manager.responseSerializer = [AFHTTPResponseSerializer serializer];
    NSString *sessionId = [[NSUserDefaults standardUserDefaults] objectForKey:@"sessionId"];
    NSDictionary *param = [NSDictionary dictionaryWithObjectsAndKeys:sessionId,@"sessionId",identity,@"identity", nil];
    NSString *url = ServerIp@"/customerApp/updateIdentity";
    [manager POST:url parameters:param progress:^(NSProgress * _Nonnull uploadProgress) {
        
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        NSDictionary *jsonDic = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableContainers error:nil];
        NSLog(@"%@",jsonDic[@"msg"]);
        [[NSUserDefaults standardUserDefaults] setObject:self.chooseTypeId forKey:@"Identity"];
        [[NSUserDefaults standardUserDefaults] synchronize];
        [self.navigationController popViewControllerAnimated:YES];
//        [self dismissViewControllerAnimated:YES completion:^{
//            HomepageViewController *homepageVc = [[HomepageViewController alloc] init];
//            [self presentViewController:homepageVc animated:YES completion:^{
//
//            }];
//            [[NSNotificationCenter defaultCenter] postNotificationName:@"userHadchooseOver" object:nil userInfo:nil];
//        }];
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        NSLog(@"错误信息%@",error);
    }];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
